//
//  ViewController.m
//  地图显示.gpx
//
//  Created by 赵雄 on 15/10/20.
//  Copyright (c) 2015年 赵雄. All rights reserved.
//

#import "ViewController.h"
#import "XMLaaaaaaaaa.h"


@interface ViewController ()<MKMapViewDelegate,NSXMLParserDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

        [self test];


//    self.mkMapView.mapType = MKMapTypeStandard;//标准模式
//   self.mkMapView.showsUserLocation = YES;//显示自己
//    
//    self.mkMapView.zoomEnabled = YES;//支持缩放
//    
//    
//    CLLocationCoordinate2D pos = {39.931203, 116.395573};//找个坐标，我是用百度坐标抓取弄的。http://api.map.baidu.com/lbsapi/getpoint/
//    
//    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(pos,2000, 2000);//以pos为中心，显示2000米
//    MKCoordinateRegion adjustedRegion = [self.mkMapView regionThatFits:viewRegion];//适配map view的尺寸
//    
//      [self.mkMapView setRegion:adjustedRegion animated:YES];
    

//    [self drawTestLine];

}

/**
 *  测试
 */

- (void)test
{
    //数据
    XMLaaaaaaaaa *xmlAaaaa = [[XMLaaaaaaaaa alloc] init];
    [xmlAaaaa start];
    
//    CLLocationCoordinate2D first = {30.638071,104.029562};
//    CLLocationCoordinate2D three = {30.638302,104.029332};
//    CLLocationCoordinate2D a = {30.637377,104.027628};
//    CLLocationCoordinate2D second = {29.660307,91.141604};

    NSString *ai = @"30.638071";
    NSString *ai2 = @"104.029562";
    
//    格式转换   双精度［doubleValue］
    CLLocationCoordinate2D first = {[ai doubleValue], [ai2 doubleValue]};

    
//    MKMapView *mapView = [[MKMapView alloc]initWithFrame:self.view.bounds];
//    mapView.delegate = self;
//    [self.view addSubview:mapView];
    self.mkMapView.delegate = self;

    //比例尺
    MKCoordinateSpan span = {30.01,30.01};
//        MKCoordinateSpan span = {.01,.01};
    
    //是否显示用户的当前位置
    //        mapView.showsUserLocation = YES;
    MKCoordinateRegion region = MKCoordinateRegionMake(first, span);
//    [self.mkMapView setRegion:region];

//    CLLocationCoordinate2D coordinate[2] = {first,second};
//    MKPolyline *line = [MKPolyline polylineWithCoordinates:coordinate count:2];
//    [self.mkMapView addOverlay:line];
    
    //多点循环付值
    for (int i = 0; i < xmlAaaaa.notes.count  ; i++) {
        NSLog(@"%d",i);
        if ( i < xmlAaaaa.notes.count - 1) {
            CLLocationCoordinate2D first = {[xmlAaaaa.notes[i] doubleValue],[xmlAaaaa.notesTow[i] doubleValue]};
            
            CLLocationCoordinate2D second = {[xmlAaaaa.notes[i+1] doubleValue],[xmlAaaaa.notesTow[i+1] doubleValue]};
            
            CLLocationCoordinate2D coordinate[2] = {first,second,};
            
            MKPolyline *line = [MKPolyline polylineWithCoordinates:coordinate count:2];
            
            [self.mkMapView addOverlay:line];
        }
        
        
    }
//    NSLog(@"%lu",xmlAaaaa.notes.count);
    [self.mkMapView setRegion:region];
}


#pragma  mark - 添加覆盖物

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    //绘制线条
    MKPolylineView *mkPolay = [[MKPolylineView alloc] initWithOverlay:overlay];
        
    mkPolay.strokeColor = [UIColor redColor];
    mkPolay.fillColor = [UIColor yellowColor];
    mkPolay.lineWidth = 3.0;
        
    return mkPolay;

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
